package com.aiyige.page.publish.selectprice.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

/**
 * Created by zhuyakun on 2018/4/8.
 */
public class PriceItem implements Parcelable {
    double priceValue;
    String priceStr;
    boolean selected;
    String priceId;

    public PriceItem() {
    }

    private PriceItem(Builder builder) {
        setPriceValue(builder.priceValue);
        setPriceStr(builder.priceStr);
        setSelected(builder.selected);
        setPriceId(builder.priceId);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public double getPriceValue() {
        return priceValue;
    }

    public void setPriceValue(double priceValue) {
        this.priceValue = priceValue;
    }

    public String getPriceStr() {
        return priceStr;
    }

    public void setPriceStr(String priceStr) {
        this.priceStr = priceStr;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }

    public String getPriceId() {
        return priceId;
    }

    public void setPriceId(String priceId) {
        this.priceId = priceId;
    }

    public static final class Builder {
        private double priceValue;
        private String priceStr;
        private boolean selected;
        private String priceId;

        private Builder() {
            selected = false;
        }

        public Builder priceValue(double priceValue) {
            this.priceValue = priceValue;
            return this;
        }

        public Builder priceStr(String priceStr) {
            this.priceStr = priceStr;
            return this;
        }

        public Builder selected(boolean selected) {
            this.selected = selected;
            return this;
        }

        public Builder priceId(String priceId) {
            this.priceId = priceId;
            return this;
        }

        public PriceItem build() {
            return new PriceItem(this);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeDouble(this.priceValue);
        dest.writeString(this.priceStr);
        dest.writeByte(this.selected ? (byte) 1 : (byte) 0);
        dest.writeString(this.priceId);
    }

    protected PriceItem(Parcel in) {
        this.priceValue = in.readDouble();
        this.priceStr = in.readString();
        this.selected = in.readByte() != 0;
        this.priceId = in.readString();
    }

    public static final Creator<PriceItem> CREATOR = new Creator<PriceItem>() {
        @Override
        public PriceItem createFromParcel(Parcel source) {
            return new PriceItem(source);
        }

        @Override
        public PriceItem[] newArray(int size) {
            return new PriceItem[size];
        }
    };

    @Override
    public boolean equals(Object obj) {
        if (obj != null && obj instanceof PriceItem) {
            PriceItem other = (PriceItem) obj;
            if (TextUtils.isEmpty(priceId) || TextUtils.isEmpty(other.priceId)) {
                return false;
            } else {
                return priceId.equals(other.priceId);
            }
        } else {
            return false;
        }
    }
}
